package com.shzu.jwc.ty.service;

import java.util.List;

import com.shzu.jwc.ty.common.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shzu.jwc.ty.bean.PeTestAppointment;
import com.shzu.jwc.ty.bean.PeTestAppointmentExample;
import com.shzu.jwc.ty.common.Semester;
import com.shzu.jwc.ty.dao.PeTestAppointmentMapper;

@Service
public class PeTestScoreservice {

	@Autowired
	PeTestAppointmentMapper mapper;
	
	@Autowired
	StudentInfoservice studentInfoservice;
	
	@Autowired
	SystemYearservice systemYearservice;

	public Integer countpetestscore(){
		return (int)mapper.countpetestscore(systemYearservice.getoneyearby(Semester.getnow()));
	}

	public Integer countselectpetestscore(Integer userStudentInfoYear,String userStudentInfoCollege){
		if(userStudentInfoYear==0)
			userStudentInfoYear=null;
		if(userStudentInfoCollege.equals("0"))
			userStudentInfoCollege=null;
	     return (int)mapper.countselectpetestscore(userStudentInfoYear,userStudentInfoCollege,systemYearservice.getoneyearby(Semester.getnow()));
    }
	
	public List<PeTestAppointment> getpetestscore(Page page){
//		PeTestAppointmentExample example=new PeTestAppointmentExample();
//		PeTestAppointmentExample.Criteria criteria=example.createCriteria();
//		criteria.andPeTestAppointmentFinalIsNotNull();
//		criteria.andSystemYearIdEqualTo(systemYearservice.getoneyearby(Semester.getnow()));
		return mapper.getpetestscore(systemYearservice.getoneyearby(Semester.getnow()),page.getStartPos(),page.getPageSize());
	}

	public List<PeTestAppointment> selectpetestscore(Integer userStudentInfoYear,String userStudentInfoCollege,Page page){
//		PeTestAppointmentExample example=new PeTestAppointmentExample();
//		PeTestAppointmentExample.Criteria criteria=example.createCriteria();
//		criteria.andPeTestAppointmentFinalIsNotNull();
//		criteria.andSystemYearIdEqualTo(systemYearservice.getoneyearby(Semester.getnow()));
		if(userStudentInfoYear==0)
			userStudentInfoYear=null;
		if(userStudentInfoCollege.equals("0"))
			userStudentInfoCollege=null;
		return mapper.selectpetestscore(userStudentInfoYear,userStudentInfoCollege,page.getStartPos(),page.getPageSize(),systemYearservice.getoneyearby(Semester.getnow()));
	}

    public List<PeTestAppointment> upselectpetestscore(Integer userStudentInfoYear,String userStudentInfoCollege,Integer peTestId) {
        PeTestAppointmentExample example=new PeTestAppointmentExample();
        PeTestAppointmentExample.Criteria criteria=example.createCriteria();
        criteria.andPeTestAppointmentFinalIsNotNull();
        criteria.andSystemYearIdEqualTo(systemYearservice.getoneyearby(Semester.getnow()));
        if(userStudentInfoYear!=0)
            criteria.andUserStudentInfoYearEqualTo(userStudentInfoYear);
        if(!userStudentInfoCollege.equals(userStudentInfoCollege))
            criteria.andUserStudentInfoCollegeEqualTo(userStudentInfoCollege);
        if(peTestId!=0)
            criteria.andPeTestIdEqualTo(peTestId);
        return mapper.selectByExample(example);
    }

	public List<PeTestAppointment> searchpetestscore(String userStudentInfoName){
		PeTestAppointmentExample example=new PeTestAppointmentExample();
		PeTestAppointmentExample.Criteria criteria=example.createCriteria();
		criteria.andPeTestAppointmentFinalIsNotNull();
		criteria.andSystemYearIdEqualTo(systemYearservice.getoneyearby(Semester.getnow()));
		criteria.andUserStudentInfoNameLike("%"+userStudentInfoName+"%");
		return mapper.selectByExample(example);
	}

}
